package com.lee.app.controller;

import com.lee.app.entity.Permission;
import com.lee.app.service.PermissionService;
import com.lee.app.util.JacksonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Lee
 */
@RestController
@RequestMapping("api/permission")
public class PermissionController {
    @Autowired
    private PermissionService permissionService;

    @RequestMapping("select-by-userid")
    public String selectByUserId(Integer id) {
        if (id == null) {
            return JacksonUtil.build(0, "用户主键不存在");
        }

        List<Permission> permissions = permissionService.selectByUserId(id);
        if (permissions != null && permissions.size() != 0) {
            return JacksonUtil.build(permissions);
        } else {
            return JacksonUtil.build(0, "用户主键不存在");
        }
    }
}
